package com.scms.secondclass.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.scms.common.annotation.Log;
import com.scms.common.core.controller.BaseController;
import com.scms.common.core.domain.AjaxResult;
import com.scms.common.enums.BusinessType;
import com.scms.secondclass.domain.ActivityEnrollment;
import com.scms.secondclass.service.IActivityEnrollmentService;
import com.scms.common.utils.poi.ExcelUtil;
import com.scms.common.core.page.TableDataInfo;

/**
 * 活动报名Controller
 * 
 * @author thy
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/secondclass/enrollment")
public class ActivityEnrollmentController extends BaseController
{
    @Autowired
    private IActivityEnrollmentService activityEnrollmentService;

    /**
     * 查询活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('secondclass:enrollment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityEnrollment activityEnrollment)
    {
        startPage();
        List<ActivityEnrollment> list = activityEnrollmentService.selectActivityEnrollmentList(activityEnrollment);
        return getDataTable(list);
    }

    /**
     * 导出活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('secondclass:enrollment:export')")
    @Log(title = "活动报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityEnrollment activityEnrollment)
    {
        List<ActivityEnrollment> list = activityEnrollmentService.selectActivityEnrollmentList(activityEnrollment);
        ExcelUtil<ActivityEnrollment> util = new ExcelUtil<ActivityEnrollment>(ActivityEnrollment.class);
        util.exportExcel(response, list, "活动报名数据");
    }

    /**
     * 获取活动报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('secondclass:enrollment:query')")
    @GetMapping(value = "/{enrollmentId}")
    public AjaxResult getInfo(@PathVariable("enrollmentId") Long enrollmentId)
    {
        return success(activityEnrollmentService.selectActivityEnrollmentByEnrollmentId(enrollmentId));
    }

    /**
     * 新增活动报名
     */
    @PreAuthorize("@ss.hasPermi('secondclass:enrollment:add')")
    @Log(title = "活动报名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityEnrollment activityEnrollment)
    {
        return toAjax(activityEnrollmentService.insertActivityEnrollment(activityEnrollment));
    }

    /**
     * 修改活动报名
     */
    @PreAuthorize("@ss.hasPermi('secondclass:enrollment:edit')")
    @Log(title = "活动报名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityEnrollment activityEnrollment)
    {
        return toAjax(activityEnrollmentService.updateActivityEnrollment(activityEnrollment));
    }

    /**
     * 删除活动报名
     */
    @PreAuthorize("@ss.hasPermi('secondclass:enrollment:remove')")
    @Log(title = "活动报名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{enrollmentIds}")
    public AjaxResult remove(@PathVariable Long[] enrollmentIds)
    {
        return toAjax(activityEnrollmentService.deleteActivityEnrollmentByEnrollmentIds(enrollmentIds));
    }
}
